/**
* @file servo.h
* @brief Header file for the servo motor control module.
*
* This file contains the function declarations and macro definitions for controlling a servo motor.
* It includes initialization functions and functions to set the angle of the servo motor.
* It also defines the GPIO pin used for PWM control and other related constants.
* @author Maker Studio
* @license Apache 2.0
* This code is open-sourced under the Apache 2.0 license. When using open-source libraries
* or code, please ensure to acknowledge the original authors and sources.
**/

#include <stdio.h>      // 标准输入输出
#include "ohos_init.h"  // 用于初始化服务(services)和功能(features)
#include "cmsis_os2.h"  // CMSIS-RTOS API V2

#include "iot_gpio.h"   // OpenHarmony HAL API：IoT硬件设备操作接口-GPIO
#include "iot_gpio_ex.h"
#include "iot_pwm.h"    // OpenHarmony HAL API：IoT硬件设备操作接口-PWM

#define SERVO_GPIO IOT_IO_NAME_GPIO_9     // PWM对应的GPIO引脚


#define COUNT 10 // 通过计算舵机转到对应角度需要发送10个左右的波形
#define SG92R_TASK_STACK_SIZE 0x1000
#define SG92R_TASK_PRIO 17
#define SERVO_GPIO 2
#define FREQ_TIME 20000

// 舵机驱动
void S92RInit(void);

void SetAngle(unsigned int duty);

/* The steering gear is centered
 * 1、依据角度与脉冲的关系，设置高电平时间为1500微秒
 * 2、不断地发送信号，控制舵机居中
 */
void RegressMiddle(void);

void ACTION_ON(void);

void ACTION_OFF(void);

void LIGHT_ON(void);

void LIGHT_OFF(void);
